package com.kuangjia.student_ems.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Entity
@Table(name = "salary_records")
@TableName("salary_records")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SalaryRecord {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(value = "id", type = com.baomidou.mybatisplus.annotation.IdType.AUTO)
    private Long id;
    
    @Column(name = "user_id", nullable = false)
    private Long userId;
    
    @Column(nullable = false)
    private Integer year;
    
    @Column(nullable = false)
    private Integer month;
    
    @Column(name = "scheme_id", nullable = true)
    private Long schemeId;
    
    @Column(name = "base_salary", nullable = false, precision = 10, scale = 2)
    private BigDecimal baseSalary;
    
    @Column(name = "attendance_deduction", precision = 10, scale = 2)
    private BigDecimal attendanceDeduction;
    
    @Column(name = "other_deduction", precision = 10, scale = 2)
    private BigDecimal otherDeduction;
    
    @Column(name = "social_security", precision = 10, scale = 2)
    private BigDecimal socialSecurity;
    
    @Column(name = "housing_fund", precision = 10, scale = 2)
    private BigDecimal housingFund;
    
    @Column(precision = 10, scale = 2)
    private BigDecimal tax;
    
    @Column(name = "total_salary", nullable = false, precision = 10, scale = 2)
    private BigDecimal totalSalary;
    
    @Column(name = "net_salary", nullable = false, precision = 10, scale = 2)
    private BigDecimal netSalary;
    
    @Column(name = "work_days")
    private Integer workDays;
    
    @Column(name = "overtime_hours", precision = 5, scale = 2)
    private BigDecimal overtimeHours;
    
    @Column(name = "performance_score", precision = 5, scale = 2)
    private BigDecimal performanceScore;
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private Status status;
    
    private String remark;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", insertable = false, updatable = false)
    @TableField(exist = false)
    private User user;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "scheme_id", insertable = false, updatable = false)
    @TableField(exist = false)
    private SalaryScheme scheme;
    
    @CreationTimestamp
    @Column(name = "create_time")
    private LocalDateTime createTime;
    
    @UpdateTimestamp
    @Column(name = "update_time")
    private LocalDateTime updateTime;
    
    public enum Status {
        PENDING,    // 待确认
        CONFIRMED,  // 已确认
        PAID        // 已发放
    }
} 